<!DOCTYPE html>
<html lang="zh_CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>变量作用域</title>
    <script>
        function fun() {
            a  = 20;//作用域为在整个script标签内，a=10与window.a=20一致
            var a = 10;//作用域在fun()函数内
        }
        fun();
        console.log(a);
    </script>
</head>

<body>

</body>

</html>